package com.czmh.etc.onlinepubsys.utils;

import java.util.Random;

/**
 * 验证码工具类
 * 
 * @author Seven
 *
 */
public class GenerateCodeUtil {
	/**
	 * 生成短信验证码
	 * 
	 * @param charCount
	 *            定义验证码的长度，如：6位，则传6
	 * @return
	 */
	public static String generateValidCode(int charCount) {
		String charValue = "";
		for (int i = 0; i < charCount; i++) {
			char c = (char) (randomInt(0, 10) + '0');
			charValue += String.valueOf(c);
		}
		return charValue;
	}

	private static int randomInt(int from, int to) {
		Random r = new Random();
		return from + r.nextInt(to - from);
	}
}
